import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;

class MijnJDialog extends JDialog {
	JButton but = new JButton("Naam invullen");
	JTextField tekst = new JTextField();

	public MijnJDialog(Frame fr, String str, boolean b) {
		super(fr, str, b);
		Container c = getContentPane();
		c.setLayout(new FlowLayout());
		tekst.setPreferredSize(new Dimension(100,20));
		c.add(tekst);
		c.add(but);
		but.setAction(new AbstractAction("Naam invullen") {
			public void actionPerformed(ActionEvent e) {
				if (e.getSource() == but) {
					((Main)MijnJDialog.this.getParent()).getNamen().add(tekst.getText());
					dispose();// venster vrij geven.
				}
			}
		});
		setSize(300, 200);
	}
}

public class Main extends JFrame {
	JDialog venstertje;
	private ArrayList<String> namen = new ArrayList<String>(); 
	JLabel label = new JLabel();
	JButton knop = new JButton();
	
	public Main() {
		setSize(400, 400);
		nieuwVenster();
		knop.setAction(new AbstractAction("Nog een naam invullen") {
			public void actionPerformed(ActionEvent e) {
				nieuwVenster();
				Main.this.label.setText(namen.toString());
			}
		});
		setVisible(true);
		Container c = getContentPane();
		c.setLayout(new FlowLayout());
		c.add(label);
		c.add(knop);
		label.setText(namen.toString());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public ArrayList<String> getNamen() {
		return namen;
	}

	public void setNamen(ArrayList<String> namen) {
		this.namen = namen;
	}
	
	public void nieuwVenster(){
		venstertje = new MijnJDialog(this, "Een naam toevoegen", true);
		venstertje.setVisible(true);
	}

	public static void main(String args[]) {
		try {
			UIManager.put("OptionPane.cancelButtonText", "Annuleren");
			UIManager.put("OptionPane.noButtonText", "Neen");
			UIManager.put("OptionPane.yesButtonText", "Ja");
			try {
				UIManager.setLookAndFeel(UIManager
						.getSystemLookAndFeelClassName());
			} catch (Exception ex) {
			}
		} finally {
			new Main();
		}

	}
}